<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%  

request.setCharacterEncoding("utf-8");

String strAction = request.getParameter("action");
String strDesId = request.getParameter("desid");

String name = request.getParameter("name");
String strareaid = request.getParameter("areaid");
String stremotionid = request.getParameter("emotionid");
String address = request.getParameter("address");
String telephone = request.getParameter("telephone");
String strtimeid = request.getParameter("timeid");
String stravgconsume = request.getParameter("avgconsume");
String strshortid = request.getParameter("shortid");
String about = request.getParameter("editorValue");

/////判空操作////////////
if(null == name || "".equals(name)){
	out.println("标题不能为空");
}
//////////

com.zipishu.DataBaseConnection db = new com.zipishu.DataBaseConnection();
Connection con = db.getConnection();
String sql="";
if("delete".equals(strAction)){
    sql = "DELETE FROM desination WHERE desid=?";
	Integer desid = Integer.parseInt(strDesId);
	PreparedStatement pstmt = con.prepareStatement(sql);
	pstmt.setInt(1, desid);
	pstmt.executeUpdate();	
}else{
int areaid = Integer.parseInt(strareaid);
int emotionid = Integer.parseInt(stremotionid);
int timeid = Integer.parseInt(strtimeid);
int shortid = Integer.parseInt(strshortid);
int avgconsume = Integer.parseInt(stravgconsume);

if(null == strDesId || "".equals(strDesId)){
	sql = "INSERT INTO desination(name,areaid,emotionid,address,telephone,timeid,avgconsume,shortid,about,createdate) VALUES (?,?,?,?,?,?,?,?,?,getdate())";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setInt(2, areaid);
pstmt.setInt(3, emotionid);
pstmt.setString(4, address);
pstmt.setString(5, telephone);
pstmt.setInt(6, timeid);
pstmt.setInt(7, avgconsume);
pstmt.setInt(8, shortid);
pstmt.setString(9, about);


pstmt.executeUpdate();

}else{
	    Integer desid = Integer.parseInt(strDesId);
		sql = "UPDATE desination SET name=?,areaid=?,emotionid=?,address=?,telephone=?,timeid=?,avgconsume=?,shortid=?,about=? WHERE desid=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, name);
		pstmt.setInt(2, areaid);
		pstmt.setInt(3, emotionid);
		pstmt.setString(4, address);
		pstmt.setString(5, telephone);
		pstmt.setInt(6, timeid);
		pstmt.setInt(7, avgconsume);
		pstmt.setInt(8, shortid);
		pstmt.setString(9, about);
		pstmt.setInt(10,desid);
	    pstmt.executeUpdate();
	}

}

con.close();

response.sendRedirect("destinationList.jsp");

%>